package com.siwei.mes.controller.erp;

import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.entity.dto.RwdextraUpdateLogDto;
import com.siwei.mes.entity.erp.RwdextraExtend;
import com.siwei.mes.entity.erp.RwdextraUpdateLog;
import com.siwei.mes.service.erp.RwdextraUpdateLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * ERP任务单修改记录相关
 *
 * @author linzi
 * @since 2024-09-09 20:36:31
 */
@Api(value = "ERP任务单修改记录")
@RestController
@RequestMapping("rwdextraUpdateLog")
public class RwdextraUpdateLogController {
    @Resource
    private RwdextraUpdateLogService rwdextraUpdateLogService;

    @ApiOperation(value = "分页获取ERP任务单修改记录")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<RwdextraUpdateLog, RwdextraUpdateLog> query) {
        return Json.succ().data(rwdextraUpdateLogService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取ERP任务单修改记录")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(rwdextraUpdateLogService.loadById(id));
    }

    @ApiOperation(value = "获取所有ERP任务单修改记录")
    @PostMapping("getAll")
    public Json getAll(@RequestBody RwdextraUpdateLog entity) {
        return Json.succ().data(ApiResult.addList(rwdextraUpdateLogService.getAll(entity)));
    }

    @ApiOperation(value = "删除任务单修改记录")
    @PostMapping("/delete")
    public Json delete(@RequestBody RwdextraUpdateLog entity) {
        rwdextraUpdateLogService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "根据主键id获取 委托编号数组")
    @GetMapping("selectExperimentByFrwdh")
    public Json selectExperimentByFrwdh(@RequestParam("updateLogId") Integer updateLogId) {
        return Json.succ().data(rwdextraUpdateLogService.selectExperimentByFrwdh(updateLogId));
    }

    @ApiOperation(value = "增补资料查询接口")
    @GetMapping("loadRwdextraById")
    public Json loadRwdextraById(@RequestParam("updateLogId") Long updateLogId) {
        return Json.succ().data(rwdextraUpdateLogService.loadRwdextraById(updateLogId));
    }

    @ApiOperation(value = "增补资料生成报告")
    @PostMapping("generateReport")
    public Json generateReport(@RequestBody RwdextraExtend entity) {
        return Json.succ().data(rwdextraUpdateLogService.generateReport(entity));
    }

    @ApiOperation(value = "增补资料保存")
    @PostMapping("updateRwdextraUpdateLog")
    public Json updateRwdextraUpdateLog(@RequestBody RwdextraExtend entity) {
        return Json.succ().data(rwdextraUpdateLogService.updateRwdextraUpdateLog(entity));
    }

    @ApiOperation(value = "批量修改ERP任务单打印修改信息(工程名称+施工单位)")
    @PostMapping("/updateBatchPrintDetailRwdextra")
    public Json updateBatchPrintDetailRwdextra(@RequestBody RwdextraUpdateLogDto rwdextraUpdateLogDto) {
        assertTrue(rwdextraUpdateLogDto.getUpdateLogIdList() == null || rwdextraUpdateLogDto.getUpdateLogIdList().isEmpty(), "请选择对应的增补资料信息");
        rwdextraUpdateLogService.updateBatchPrintDetailRwdextra(rwdextraUpdateLogDto);
        return Json.succ().data(new ApiResult());
    }
}
